#include "memPage_t.h"

memPage_t::memPage_t(int size)
{
	_usedSpace = 0;
	_current = 0;
	_capacity = size;
	_page = new byte[size];

}

memPage_t::~memPage_t() 
{
	delete[] _page;
}

bool memPage_t::isPageFull()
{
	return _usedSpace == _capacity;
}
bool memPage_t::isPageEmpty()
{
	return _usedSpace == 0;
}

void memPage_t::setPosition(int position)
{
	_current = position;
}

int memPage_t::getPosition()
{
	return _current;
}

int memPage_t::getCapacity()
{
	return _capacity;
}

int memPage_t::getActualSize()
{
	return _usedSpace;
}

void memPage_t::write(byte* data, int size, int position = -1)
{
	if (position == -1) 
	{
		position = _current;
		
	}

	if (_usedSpace < position + size )
		_usedSpace = position + size;

	memcpy(_page + position, data, size);
}

byte* memPage_t::read(int position)
{
	if (position == -1) 
	{
		position = _current;
	}
	return _page+position;
}


void memPage_t::setNextPage(memPage_t *nextPage)
{
	_nextPage = nextPage;
}

memPage_t &memPage_t::getNextPage()
{
	return *_nextPage;
}


